package com.starview.star.operators.pio.runtime;

import java.nio.ByteBuffer;

public class ByteBufferBindings {

  public static ByteBuffer _bb_allocate_direct(int capacity) {
    return ByteBuffer.allocateDirect(capacity);
  }

  public static String _bb_to_string(ByteBuffer bb) {
    return bb.toString();
  }

  public static void _bb_putWord8(ByteBuffer bb, int b) {
    bb.put((byte)(b & 0xFF));
  }

  public static int _bb_getWord8(ByteBuffer bb) {
    return bb.get() & 0xFF;
  }

  public static void _bb_putWord16(ByteBuffer bb, int s) {
    bb.putShort((short)(s & 0xFFFF));
  }

  public static int _bb_getWord16(ByteBuffer bb) {
    return bb.getShort() & 0xFFFF;
  }

  public static void _bb_putWord32(ByteBuffer bb, int i) {
    bb.putInt(i);
  }

  public static int _bb_getWord32(ByteBuffer bb) {
    return bb.getInt();
  }

  public static void _bb_putWord64(ByteBuffer bb, long l) {
    bb.putLong(l);
  }

  public static long _bb_getWord64(ByteBuffer bb) {
    return bb.getLong();
  }

  public static void _bb_putByteBuffer(ByteBuffer dst, ByteBuffer src) {
    dst.put(src);
  }

  public static ByteBuffer _bb_getByteBuffer(ByteBuffer bb, int size) {
    byte[] buffer = new byte[size];
    bb.get(buffer);
    return ByteBuffer.wrap(buffer);
  }

  public static void _bb_flip(ByteBuffer bb) {
    bb.flip();
  }

  public static void _bb_clear(ByteBuffer bb) {
    bb.clear();
  }

  public static void _bb_compact(ByteBuffer bb) {
    bb.compact();
  }

  public static boolean _bb_hasRemaining(ByteBuffer bb) {
    return bb.hasRemaining();
  }

  public static int _bb_remaining(ByteBuffer bb) {
    return bb.remaining();
  }

  public static ByteBuffer _bb_asReadOnlyBuffer(ByteBuffer bb) {
    return bb.asReadOnlyBuffer();
  }

  public static int _bb_position(ByteBuffer bb) {
    return bb.position();
  }

  public static void _bb_set_position(ByteBuffer bb, int pos) {
    bb.position(pos);
  }

  public static int _bb_limit(ByteBuffer bb) {
    return bb.limit();
  }

  public static void _bb_set_limit(ByteBuffer bb, int limit) {
    bb.limit(limit);
  }

  public static int _bb_capacity(ByteBuffer bb) {
    return bb.capacity();
  }

  public static ByteBuffer _bb_slice(ByteBuffer bb) {
    return bb.slice();
  }

}
